<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>

    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>

    <script type="text/javascript" src="../script/mobile-detect.js"></script>
    <script type="text/javascript" src="../script/mobile-detect.min.js"></script>

</head>
<body>
<div id="secHeader">
  <header class="header">
      <!--<a href="javascript:void(0);"  class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>-->
      <h2>注册</h2>
      <a href="javascript:void(0);" onclick="aaplay('login')" class="qiandao_btn"  style="position: absolute;  right: 3%; top: 0; color: #fff;">直接登录</a>
  </header>
</div>
<section class="login_section">
    <div class="fyb_logo"><img src="../image/fyb_logo.png" alt=""></div>
    <div class="login_box">
        <ul>
            <li class="username"><input type="text" placeholder="请输入手机号" id='phone' name="phone"></li>
            <li class="tel_code"><input type="text" placeholder="请输入验证码" id='yzm' name="yzm"><span id="regyzm">获取验证码</span></li>
            <li class="tel_code"><input type="password" placeholder="请设置密码"  id='password'></li>
            <li style="display:none" class="user_code"><input type="text" placeholder="请输入推荐人邀请码(选填)"  id='idno' value=""></li>
        </ul>
        <p class="agree">成功登陆即表示您同意<a href="aaplay('yhxy')">《用户协议》</a></p>
        <button class="login_submit" type="submit" onclick="reg()">进入法援宝</button>
    </div>
    <div class="login_kinds showhide" style="display: none">
        <h6><span>第三方登录</span></h6>
        <ul>
            <li><a href="javascript:;" onclick="sanfang_qq()"><img src="../image/ologin1.png" alt=""></a></li>
            <li><a href="javascript:;" onclick="initWXBind()"><img src="../image/ologin2.png" alt=""></a></li>
            <li><a href="javascript:;" onclick="initWBBind()"><img src="../image/ologin3.png" alt=""></a></li>
        </ul>
    </div>
</section>
<aside class="download showhide">
    <a href="##" class="user_download">普通用户点击下载【法援宝】</a>
</aside>


</body>

<script>
    var mt
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });


        var md = new MobileDetect(
            'Mozilla/5.0 (Linux; U; Android 4.0.3; en-in; SonyEricssonMT11i' +
            ' Build/4.1.A.0.562) AppleWebKit/534.30 (KHTML, like Gecko)' +
            ' Version/4.0 Mobile Safari/534.30');

       var os = md.os();//获取系统  
       if (os == "iOS") {//ios系统的处理  
           mt=2
       }else if(os == "AndroidOS") {//Android系统的处理  
           mt=1
       }

        apk()
    }
    function apk(){
        if(mt==1){
            var p={id:31};
        }else {
           var p={id:32};
        }
        api.ajax({
            url: webSiteUrl+'/app/public/ad',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {


            if(ret.code==200){

                var tj=ret.data;
                if(tj != null){
                    $('.user_download').attr('href',webSiteUrl+tj.file);
                    $('.user_download').attr('download',webSiteUrl+tj.file);

                }
            }

        });

    }

    function showhide(){
        api.ajax({
            url: webSiteUrl+'/app/home/showhide',
            method: 'post',
            data: {


            }
        }, function(ret, err) {

            if(ret.code==200){

               $('.showhide').hide();

            }
        });

    }
    function reg(){
        var phone=$("#phone").val();
        var password=$("#password").val();
        var yzm=$("#yzm").val();
        var idno=$("#idno").val();
        if(phone==''){
            alert("请输入手机号！");return;
        }else if(phone.length != 11){
            alert("手机号格式错误！");return;
        }else if(yzm==''){
            alert("请输入验证码！");return;
        }else if(password==''){
            alert("请输入密码");return;
        }else if(!/^(\w){6,20}$/.test(password)){
            alert("密码必须是6-20个字母、数字、下划线！");return;
        }

        var p={phone:phone,password:password,yzm:yzm,idno:idno,type:2};
        api.ajax({
            url: webSiteUrl+'/app/public/reg',
            method: 'post',
            data: {
                values: p
            }
        }, function(ret, err) {
            if(ret.code==200){

                alert(ret.msg);
                $api.clearStorage();
                $api.setStorage('user',ret.data);
                $api.setStorage('phone',phone);

                aaplay('workbench')


            }else{alert(ret.msg)}
        });

    }

    $('#regyzm').click(function () {
        if($(this).hasClass('regyzm')==false){
            var phone=$('input[name=phone]').val();
            if(phone==''){
                alert("请输入手机号！");return;
            }else if(phone.length != 11){
                alert("手机号格式错误！");return;
            }

            var p={phone:phone,type:2};
            api.ajax({
                url: webSiteUrl+'/app/public/yzm',
                method: 'post',
                data: {

                    values: p
                }
            }, function(ret, err) {
                if(ret.code==200){

                    $('#regyzm').addClass('regyzm');
                    var num=60;
                    timer=setInterval(function(){
                        $('#regyzm').html(num+'秒');
                        num--;
                        if(num==0){
                            clearInterval(timer);
                            timer=null;
                            $('#regyzm').html('重新获取');
                            $('#regyzm').removeClass('regyzm');
                        }
                    },1000)

                    alert(ret.msg)

                }else{alert(ret.msg)}
            });

        }
    })

        //qq登录
       function sanfang_qq(){
            var qq = api.require('qq');
            var openId = '';
            qq.installed(function(ret, err) {
                if (!ret.status) {
                    api.alert({ msg: "当前设备未安装QQ客户端" });
                } else {
                    qq.login(function(ret, err) {
                        if (ret.status) {
                            openId = ret.openId;
                            qq.getUserInfo(function(ret, err) {
                                if (ret.status) {
                                    QQbindAccount(openId,ret.info.nickname,ret.info.figureurl_qq_1);
                                } else {
                                    api.alert({ msg: err.msg });
                                }
                            });
                        }
                    });
                }
            });
        }



        //qq登录传值
        function QQbindAccount(openid,nickname,imurl){

            var d = {openid:openid,type:1,'username':nickname,icon:imgurl};
            api.ajax({
                url: webSiteUrl+'/App/public/three',
                method: 'post',
                data: {
                    values: d
                }
            }, function(ret, err) {
                if (ret.code == 200) {

                    $api.setStorage("user",ret.data);
                    location.href='index.html';

                    // //发送监听
                    // api.sendEvent({
                    //     name:'loginEvent'
                    // });

                }else{
                    alert(ret.msg);

                }
            });
        }



        //微信登录
        function initWXBind() {

            var wx = api.require('wx');
            var code = '';
            wx.isInstalled(function(ret, err) {
                if (!ret.installed) {
                    alert("当前设备未安装微信客户端");
                } else {
                    wx.auth({
                        apiKey: 'wx4dc49bc6ce410719'
                    }, function(ret, err) {
                        if (ret.status) {
                            wx.getToken({
                                apiKey: 'wx4dc49bc6ce410719',
                                apiSecret: '8c22083560ad2c3b607a5b47bcc09a71',
                                code: ret.code
                            }, function(ret, err) {
                                if (ret.status) {
                                     api.showProgress({
                                        style: 'default',
                                        animationType: 'fade',
                                        title: '授权成功',
                                        text: '绑定处理中...',
                                        modal: true
                                    });
                                     wx.getUserInfo({
                                        accessToken: ret.accessToken,
                                        openId: ret.openId
                                    }, function(ret, err) {

                                        if (ret.status) {
                                            // 绑定成功

                                            WXbindAccount(ret.openid,ret.nickname,ret.headimgurl);
                                            api.hideProgress();


                                        }
                                    });
                                } else {
                                    alert(err.code);
                                }
                            });
                    }
                    });
                }
            });
        }

        //微信传值
        function WXbindAccount(openid,nickname,imgurl) {

            var s = {openid:openid,type:2,'username':nickname,icon:imgurl};

            api.ajax({
                url: webSiteUrl+'/App/public/three',
                method: 'post',
                data: {
                    values: s
                }
            }, function(ret, err) {
                if (ret.code == 200) {

                    $api.setStorage("user",ret.data);



                }else{
                    alert(ret.msg);

                }
            });
        }



        //微博登录
         function initWBBind() {
            var weibo = api.require('weibo');
            weibo.isInstalled(function(ret) {
                if (!ret.status) {
                    alert('未安装新浪微博客户端');
                } else {
                    weibo.auth(function(ret, err) {
                        if (ret.status) {
                            weibo.getUserInfo({
                                token: ret.token,
                                userId: ret.userId
                            }, function(ret, err) {
                                if (ret.status) {

                                    WBbindAccount(ret.userInfo.id,ret.userInfo.screen_name,ret.userInfo.profile_imageurl);
                                }
                            });
                        }
                    });
                }
            });
        }

        //微博传值
        function WBbindAccount(openid,nickname,imgurl) {
            var s = {openid:openid,type:3,'username':nickname,icon:profile_imageurl};

            api.ajax({
                url: webSiteUrl+'/App/public/three',
                method: 'post',
                data: {
                    values: s
                }
            }, function(ret, err) {

                if (ret.code == 200) {

                    $api.setStorage("user",ret.data);
                   location.href='index.html';


                }else{
                    alert(ret.msg);

                }
            });
        }

</script>
</html>
